﻿using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CLVisionHalconNC620.Dialogs
{
    public partial class ShowResult : Form
    {
        private ShowResult()
        {
            InitializeComponent();
        }
        private static volatile ShowResult _instance = null;
        private static readonly object o = new object();

        public static ShowResult GetInstance()
        {
            if (_instance == null || _instance.IsDisposed)
            {
                lock (o)
                {
                    if (_instance == null || _instance.IsDisposed)
                    {
                        _instance = new ShowResult();
                    }
                }
            }
            return _instance;
        }

        private void ShowResult_FormClosed(object sender, FormClosedEventArgs e)
        {
            _instance = null;
        }
        /// <summary>
        /// 注册窗体滚轮事件，实现图像缩放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public  void CustomMouseWheel(Form frm, HSmartWindowControl hSmartWindowControl, object sender, MouseEventArgs e)
        {
            System.Drawing.Point pt = frm.Location;
            int leftBorder = hSmartWindowControl.Location.X;
            int rightBorder = hSmartWindowControl.Location.X + hSmartWindowControl.Size.Width;
            int topBorder = hSmartWindowControl.Location.Y;
            int bottomBorder = hSmartWindowControl.Location.Y + hSmartWindowControl.Size.Height;
            //判断鼠标指针是否在控件内部
            if (e.X > leftBorder && e.X < rightBorder && e.Y > topBorder && e.Y < bottomBorder)
            {
                MouseEventArgs newe = new MouseEventArgs(e.Button, e.Clicks, e.X - pt.X, e.Y - pt.Y, e.Delta);
                hSmartWindowControl.HSmartWindowControl_MouseWheel(sender, newe);
            }
        }

        private void ShowResult_Load(object sender, EventArgs e)
        {
            this.MouseWheel += mouseWheel;
        }
        private void mouseWheel(object sender, MouseEventArgs e)
        {
          CustomMouseWheel(this, hSmartWindowControl1, sender, e);
        }
    }
}
